﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.Collections;
using Gin.Transactions;

namespace Gin.Commands
{
public class CommandSequence : TransactionalCommand, IContainerCommand
{

    [GinArgumentCommand(AllowMultiple = true)]
    public List<Command> Commands { get; set; }

    public override void Do(ExecutionContext context)
    {
        foreach (Command command in Commands)
        {
            command.Do(context);
        }
    }

    public override TransactionStep Do(ExecutionContext context, Transaction transaction)
    {
        foreach (Command command in Commands)
        {
            if (command is TransactionalCommand)
            {
                ((TransactionalCommand)command).Do(context, transaction);
            }
            else
            {
                command.Do(context);
            }
        }
        return null;
    }

    public override void Rollback(TransactionStep step)
    {
    }

    public IEnumerable<Command> InnerCommands
    {
        get
        {
            return Commands;
        }
    }

}
}
